package com.qf.controller;

import com.qf.cache.ChannelCache;
import com.qf.dto.R;
import com.qf.entity.TChannel;
import com.qf.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
杨威
2021/11/6
14:41
*/
@RestController
@RequestMapping("/channel")
public class ChannelController {
    @Autowired
    ChannelCache channelCache;
    @Autowired
    ChannelService channelService;
    @GetMapping("all")
    public R findAll(){
        List allData = channelCache.getAllData();
        return R.setOk(allData);
    }
    @GetMapping("/findById")
    public R findById(Long id){
        TChannel channelCacheById = channelCache.getById(id);
        return R.setOk(channelCacheById);
    }
    @PostMapping("/add")
    public R add(TChannel tChannel){
        channelService.add(tChannel);
        return R.setOk();
    }
    @DeleteMapping("/delete")
    public R delete(Integer id){
        channelService.remove(id);
        return R.setOk();
    }
    @PostMapping("/update")
    public R update(TChannel tChannel){
        channelService.modify(tChannel);
        return R.setOk();
    }
}
